home *** CD-ROM | disk | FTP | other *** search
/ Hack-Mag 7 / Hack-Mag - Issue 7 (1991-11-27)(D-Tect)(PD).adf / Sources / DrawLine.s next >
Text File  |  1991-11-25  |  4KB  |  147 lines

  1. *************************************************************************
  2. *                                    *
  3. *                   Line Routine for one plane, by TIP            *
  4. *            RELEASED IN HACK-MAG #7                *
  5. *************************************************************************
  6.  
  7. ; Internal Version: 1.01
  8.  
  9. ; - assemble defs -------------------------------------------------------
  10.  
  11. DL_Width = 40
  12. DL_Fill  = 0            ;0: NOFILL 1:FILL
  13.  
  14. ; - internal ------------------------------------------------------------
  15.  
  16.  ifeq DL_Fill
  17. DL_MInterns = $ca
  18.  else
  19. DL_MInterns = $4a
  20.  endc
  21.  
  22. ; ------------- the routine itsself -------------------------------------
  23. ;Needs:
  24. ; a0    planept
  25. ; a6    $dff002
  26. ; d0/d1 x,y start pos
  27. ; d2/d3 x,y end   pos
  28. ; d4    Width of plane
  29.  
  30. ;Kills:
  31. ; d0-d4/a0-a1 (+d5 in Fill Mode)
  32.  
  33. DrawLine:    cmp.w    d1,d3            ;   drawing only from top to bottom is
  34.         bge.s    .y1ly2            ;   necessary for:
  35.         exg    d0,d2            ;   a: up-down differences (same koords)
  36.         exg    d1,d3            ;   b: blitter invert bit (only at top of line)
  37.  
  38. .y1ly2:        sub.w    d1,d3            ;d3:yd
  39.  
  40. ; here we could do an optimization with special shifts
  41. ; depending on the DL_Width value ... i know it, but please, let it be.
  42.  
  43.         mulu    d4,d1            ;   use muls for neg y-vals
  44.         add.l    d1,a0            ;   please don't use add.w here!
  45.         moveq    #0,d1            ;d1:quant-counter
  46.         sub.w    d0,d2            ;d2:xd
  47.         bge.s    .xdpos
  48.         addq.w    #2,d1            ;   set bit 1 of quant-counter (here it could be a moveq)
  49.         neg.w    d2
  50. .xdpos:        moveq    #$f,d4            ;   d4 full cleaned (for later oktants move.b)
  51.         and.w    d0,d4
  52.     ifne    DL_Fill
  53.         move.b    d4,d5            ;d5:special fill bit
  54.         not.b    d5
  55.     endc
  56.         lsr.w    #3,d0            ;   yeah, on byte (necessary for bchg) ....
  57.         add.w    d0,a0            ;   ... blitter ands automagically
  58.         ror.w    #4,d4            ;d4:shift
  59.         or.w    #$b00+DL_MInterns,d4    ;   bltcon0-codes
  60.         swap    d4
  61.         cmp.w    d2,d3            ;   which delta is the biggest?
  62.         bge.s    .dygdx
  63.         addq.w    #1,d1            ;   set bit 0 of quant-counter
  64.         exg    d2,d3            ;   exchange xd with yd
  65. .dygdx:        add.w    d2,d2            ;d2:xd*2
  66.         move.w    d2,d0            ;d0:save for $52(a6)
  67.         sub.w    d3,d0            ;d0:xd*2-yd
  68.         addx.w    d1,d1            ;Bit0:sign-bit
  69.         move.b    .oktants(pc,d1.w),d4    ;   in low byte of d4 (upper byte cleaned above)
  70.         swap    d2
  71.         move.w    d0,d2
  72.         sub.w    d3,d2            ;d2:2*(xd-yd)
  73.         moveq    #6,d1            ;d1:shiftval(not necessary) + testval for the blitter
  74.         lsl.w    d1,d3            ;d3:BLTSIZE
  75.         add.w    #$42,d3
  76.         lea    $52-2(a6),a1        ;a1:CUSTOM + $52
  77.  
  78. ; WARNING:  if you use fastmem and an extreme DMA-Access (e.g.  6
  79. ; planes and copper), you should insert a tst.b (a6) here (for the
  80. ; shitty AGNUS-BUG).
  81.  
  82. .wb:        btst    d1,(a6)            ;   waiting for the blitter ...
  83.         bne.s    .wb
  84.     ifne    DL_Fill
  85.         bchg    d5,(a0)            ;   inverting the first bit of line.
  86.     endc
  87. ; ------------- Not necessary, should never be used. Only for testing purposes.
  88. ;        move.w    #$8000,$74-2(a6)
  89. ;        move.w    #-1,$44-2(a6)
  90. ;        move.w    #-1,$72-2(a6)
  91. ;        move.w    #DL_Width,$60-2(a6)
  92. ;        move.w    #DL_Width,$66-2(a6)
  93. ; -------------
  94.         move.l    d4,$40-2(a6)        ;   writing to the blitter regs as fast as possible.
  95.         move.l    d2,$62-2(a6)
  96.         move.l    a0,$48-2(a6)
  97.         move.w    d0,(a1)+
  98.         move.l    a0,(a1)+        ;   shit-word buffer pt.
  99.         move.w    d3,(a1)
  100.         rts
  101.  
  102. ; ------------- oktant-table --------------------------------------------
  103.  
  104.     ifne    DL_Fill
  105. SML = 2
  106.     else
  107. SML = 0
  108.     endc
  109.  
  110. .oktants:    dc.b    SML+1,SML+1+$40
  111.         dc.b    SML+17,SML+17+$40
  112.         dc.b    SML+9,SML+9+$40
  113.         dc.b    SML+21,SML+21+$40
  114.  
  115. ; ------------- optimized init-part -------------------------------------
  116.  
  117. ; Needs:
  118. ; a6:co
  119.  
  120. ; Kills:
  121. ; d0-d2
  122.  
  123. DL_Init:    addq.w    #2,a6
  124.         moveq    #-1,d1
  125.     ifgt    DL_Width-127
  126.         move.w    #DL_Width,d0
  127.     else
  128.         moveq    #DL_Width,d0
  129.     endc
  130.         moveq    #6,d2
  131. .wb:        btst    d2,(a6)
  132.         bne.s    .wb
  133.         move.w    d1,$44-2(a6)
  134.         move.w    d1,$72-2(a6)
  135.         move.w    #$8000,$74-2(a6)
  136.         move.w    d0,$60-2(a6)
  137.         move.w    d0,$66-2(a6)
  138.         rts
  139.  
  140. ; ------------- exit-part -----------------------------------------------
  141.  
  142. DL_Exit:    subq.w    #2,a6
  143.         rts
  144.  
  145.  
  146.         end
  147.